import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
const path = require('path')
import alias from '@rollup/plugin-alias';
// import legacyPlugin from '@vitejs/plugin-legacy'

// https://vitejs.dev/config/
export default defineConfig({
  base: './',//js、css的前缀，./是为了兼容cordova部署
  plugins: [
    vue(),
    alias({
      entries: [
        { find: '@', replacement: path.resolve(__dirname, './src/') }
      ]
    }),
    doPlugin(),
  ],
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: `
        @import "./src/sass/variable";
        @import "./src/sass/mixin";
        `,
      }
    }
  },
  server: {
    host: true,
  },
  build: {
    outDir: 'www'//输出文件夹
  },
})


function doPlugin() {
  return {
    name: 'do-config',
    configResolved(config) {
      let d = new Date();
      d = '' + d.getFullYear() + (d.getMonth() + 1) + d.getDate() + d.getHours() + d.getMinutes() + d.getSeconds()
      config.env.VITE_VERSION = 'V 2.2.0.' + d
      console.log(config.env)
      return config
    },
  }
}
